﻿using System.ComponentModel;
using System.Diagnostics;
using Fujitsu.JiraAnalysis.Common;


namespace Fujitsu.JiraAnalysis.ReplicationService
{
    [RunInstaller(true)]
    public partial class CustomInstaller : System.Configuration.Install.Installer
    {
        public CustomInstaller()
        {
            InitializeComponent();
        }
        public override void Install(System.Collections.IDictionary stateSaver)
        {
            base.Install(stateSaver);

            if (!EventLog.SourceExists(EventLogWrapper.SOURCE))
            {
                EventLog.CreateEventSource(EventLogWrapper.SOURCE, EventLogWrapper.LOGNAME);

            }
            EventLogger.CreateInstance(new EventLogWrapper()).LogWrite(string.Format("Event log '{0}' is created.", EventLogWrapper.LOGNAME));
        }
        public override void Uninstall(System.Collections.IDictionary savedState)
        {
            base.Uninstall(savedState);
            RemoveLog();
        }
        public override void Rollback(System.Collections.IDictionary savedState)
        {
            base.Rollback(savedState);
            RemoveLog();
        }

        public void RemoveLog()
        {
            if (EventLog.SourceExists(EventLogWrapper.SOURCE))
            {
                EventLog.DeleteEventSource(EventLogWrapper.SOURCE);
            }
            if (EventLog.Exists(EventLogWrapper.LOGNAME))
            {
                EventLog.Delete(EventLogWrapper.LOGNAME);
            }
        }
    }
}
